package com.ruoyi.keep.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.keep.domain.NumberCard;
import com.ruoyi.keep.service.INumberCardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 次数卡规格Controller
 * 
 * @author ruoyi
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/keep/cardNum")
public class NumberCardController extends BaseController
{
    @Autowired
    private INumberCardService numberCardService;

    /**
     * 查询次数卡规格列表
     */
    @PreAuthorize("@ss.hasPermi('keep:cardNum:list')")
    @GetMapping("/list")
    public TableDataInfo list(NumberCard numberCard)
    {
        startPage();
        List<NumberCard> list = numberCardService.selectNumberCardList(numberCard);
        return getDataTable(list);
    }

    /**
     * 导出次数卡规格列表
     */
    @PreAuthorize("@ss.hasPermi('keep:cardNum:export')")
    @Log(title = "次数卡规格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NumberCard numberCard)
    {
        List<NumberCard> list = numberCardService.selectNumberCardList(numberCard);
        ExcelUtil<NumberCard> util = new ExcelUtil<NumberCard>(NumberCard.class);
        util.exportExcel(response, list, "次数卡规格数据");
    }

    /**
     * 获取次数卡规格详细信息
     */
    @PreAuthorize("@ss.hasPermi('keep:cardNum:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(numberCardService.selectNumberCardById(id));
    }

    /**
     * 新增次数卡规格
     */
    @PreAuthorize("@ss.hasPermi('keep:cardNum:add')")
    @Log(title = "次数卡规格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NumberCard numberCard)
    {
        return toAjax(numberCardService.insertNumberCard(numberCard));
    }

    /**
     * 修改次数卡规格
     */
    @PreAuthorize("@ss.hasPermi('keep:cardNum:edit')")
    @Log(title = "次数卡规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NumberCard numberCard)
    {
        return toAjax(numberCardService.updateNumberCard(numberCard));
    }

    /**
     * 删除次数卡规格
     */
    @PreAuthorize("@ss.hasPermi('keep:cardNum:remove')")
    @Log(title = "次数卡规格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(numberCardService.deleteNumberCardByIds(ids));
    }
}
